package com.five.controller.backstage;

import com.five.dao.backstage.RoomQueDao;
import com.five.entity.backstage.TRoomQuery;
import com.five.util.LayTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * Created by IntelliJ IDEA.
 * User: jianglin
 * Date: 2020/11/23  15:43
 */

@RestController
@RequestMapping("roomquery")
public class RoomQuerController {
    @Autowired
    private RoomQueDao getRoom;

    @RequestMapping("/queryRoom")
    //查询所有数据
    public LayTable queryRoom(Integer page, Integer limit,TRoomQuery tRoomQuery) {
        //查询数据总条数
        int a = getRoom.getAllCount(tRoomQuery);
        //查询出所有角色的信息，封装到laytable中
        List<Map> maps = getRoom.queryAll(page, limit,tRoomQuery);
        LayTable table = new LayTable(a, maps);
        return table;
    }

    //通过id进行删除
    @RequestMapping("/deleteId")
    public int deleRoom(int id) {
        int i = getRoom.deleteId(id);
        return i;
    }

    //出查询
    @RequestMapping("/addRoomQuery")
    public int addRoom(TRoomQuery tRoomQuery) {
        int i = getRoom.addRoom(tRoomQuery);
        return i;
    }

    @RequestMapping("/queryRoomType")
    public List<Map> queryRoomType() {
        List<Map> m = getRoom.queryRoomType();
        return m;
    }

    @RequestMapping("/selectRoomNumber")
    public List<Map> selectRoomNumber(String roomcode) {
        List<Map> map = getRoom.selectRoomNumber(roomcode);
        return map;
    }

    //修改
    @RequestMapping("/updateRoom")
    public int updateRoom(TRoomQuery tRoomQuery) {
        //TRoomQuery tRoomQuery = new TRoomQuery(id, roomcode,typeid);
        int result = getRoom.updata(tRoomQuery);
        return result;
    }

    @RequestMapping("bad")
    public int updata(Integer id){
        int i=getRoom.bad(id);
        if (i>0){
            return i;
        }
        return -1;
    }
    @RequestMapping("good")
    public int updatagood(Integer id){
        int i=getRoom.good(id);
        if (i>0){
            return i;
        }
        return -1;
    }

}
